<template>
  <div>
    <el-row class="">
      <el-col :span="8">工单配件详情列表</el-col>
      <el-col :span="16">
        <el-form
          :inline="true"
          ref="searchOptions"
          :model="searchOptions"
          label-width="90px"
          label-position="right"
        >
          <el-form-item>
            <el-select
              clearable
              ref="dragSelect"
              placeholder="状态"
              v-model="searchOptions.status"
              class="drag-select"
            >
              <el-option
                v-for="item in dict['配件单状态']"
                :key="item.id"
                :value="item.value"
                :label="item.text"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select
              clearable
              ref="dragSelect"
              placeholder="配件类别"
              v-model="searchOptions.partsType"
              class="drag-select"
            >
              <el-option
                v-for="item in dict['汽车配件类型']"
                :key="item.id"
                :value="item.value"
                :label="item.text"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input
              clearable
              v-model="searchOptions.likeName"
              placeholder="库存编号/配件编号"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              @click="seach"
            >搜索</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-divider content-position="center"></el-divider>
    <el-row>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #allNum>
          <div class="tabelAomut">
            <div>
              配件总金额：<span>￥{{ projectSum }}</span>
            </div>
            <div>
              出库数：<span>{{ outboundNum + '/' + partsNum }}</span>
            </div>
          </div>
        </template>
      </data-table>
    </el-row>
  </div>
</template>

<script>
import { rapidPartsPage } from '@/api/after-sale/workOrderManage/fast' //快速单子api
import { synthesizePartsPage } from '@/api/after-sale/workOrderManage/comprehensive';//综合单api
import baseMixin from '@/mixins/base'
import { getDict } from '@/utils'

export default {
  name: 'carInfo',
  components: {},
  props: ['workOrderId', 'workOrderType', "workOrderCode"], // workOrderType 工单类型 1快速单
  mixins: [
    baseMixin({
      // findData: rapidPartsPage,
      dataName: ['content', 'totalRecords'],
      idName: 'id',
    }),
  ],
  computed: {
    //总数
    partsNum () {
      let sum = 0
      this.tableData.forEach((element) => {
        sum += Number(element.num)
      })
      return sum
    },
    //出库数
    outboundNum () {
      let sum = 0
      this.tableData.forEach((element) => {
        if (element.status != '未出库') {
          sum += Number(element.num)
        }
      })
      return sum
    },
    projectSum () {
      let sum = 0
      this.tableData.forEach((element) => {
        sum += Number(element.amount)
      })
      return sum.toFixed(2)
    },
  },
  data () {
    return {
      searchOptions: {
        likeName: '', //配件编号
        partsType: '', //配件类比
        status: '',
      },
      dict: {},
      tableColumnAttributes: [
        { name: '库存编号', value: 'stockCode', type: 'text' },
        { name: '配件编号', value: 'partsCode', type: 'text' },
        { name: '配件名称', value: 'partsName', type: 'text' },
        { name: '配件类别', value: 'partsType', type: 'text' },
        { name: '配件单位', value: 'partsUnit', type: 'text' },
        { name: '配件仓位', value: 'storageSiteName', type: 'text' },
        { name: '仓位编号', value: 'storageSiteCode', type: 'text' },
        { name: '采购成本', value: 'purchasePrice', type: 'text' },
        { name: '销售价', value: 'storagePrice', type: 'text' },
        { name: '出库单价', value: '', type: 'text' },
        { name: '状态', value: 'status', type: 'text' },
        { name: '出库人', value: 'userName', type: 'text' },
        { name: '出库时间', value: 'outTime', type: 'text' },
      ],
    }
  },
  async created () {
    this.dict = getDict(['配件单状态', '汽车配件类型'])
    this.notQuery = false;
    this.searchOptions[`sourceCode`] = this.workOrderCode
    this.setTableData()
  },
  methods: {
    async setTableData () {
      if (!this.notQuery) {
        let fun = this.$parent.getConfig.orderFittingList;
        if (fun) {
          let res = await fun(this.searchOptions, this.pageSize, this.currentPage);
          if (res.success) {
            this.totalCount = parseInt(res.data['totalRecords'])
            this.tableData = res.data['content'];
          }

        }
      }
    },
    seach () {
      this.currentPage = 1
      this.setTableData()
    },
    changeType (item) {
      this.selectedTypeText = item.label
    },
  },
  mounted () { },
}
</script>

<style lang="scss" scoped>
</style>
